﻿#include<stdio.h>
int main()
{
	int year, month, day, days;     //定义变量
	void H(int year, int days, int* pm, int* pd);//函数说明并且定义指针变量*pm*pd
	printf("输入年份以及天数:");
	scanf_s("%d %d", &year, &days);
	H(year, days, &month, &day);         //将month和day的地址穿给形参*pm和*pd，并调用H函数
	printf("日期是%d-%d-%d", year, month, day);
	return 0;
}
void H(int year, int days, int* pm, int* pd)
{
	int i, r; 
	int tab[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
	{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };//定义二维数组来记录闰年与非闰年的日期
	r = (year % 4 == 0 && year % 100 != 0) || (year % 400 != 0);//判断是否为闰年，条件成立为1，反而否之

	for (i = 1; days > tab[r][i]; i++)
		days -= tab[r][i];      //逐个排除月日直至days小于某月某日，即等于某月某日
	*pm = i;
	*pd = days; //指针间接访问month和day并修改其值
}
